<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>首页</title>
    <script type="text/javascript">
        var path = window.document.location.href;
        var pathName = window.document.location.pathname;
        var hostPath = path.substring(0, path.indexOf(pathName));
        var projectName = pathName.substring(0, pathName.substr(1).indexOf("/") + 1);
        document.write('<scr' + 'ipt src="' + projectName + '/js/html/header.js"></scr' + 'ipt>');
        document.write('<link rel="stylesheet" type="text/css" href="' + projectName + '/css/basic/login_css.css">');
    </script>
    <script type="text/javascript">
        var checkCode = false;
        $.ajax({
            type: "GET",
            url: projectName + "/index/param",
            dataType: "json",
            success: function (data) {
                var indexParam = data.entity;
                checkCode = indexParam.checkCode;
                if (checkCode) {
                    changecode(document.getElementById("codeimg"));
                    $("#login_form_checkcode").show();
                } else {
                    $("#login_form_checkcode").hide();
                }
                $("#login_sysName").html(indexParam.sysName);
                $(document).attr("title", indexParam.sysName);
            }
        });
    </script>
    <script type="text/javascript">
       
        $("#codeimg").attr('src', projectName + "/images/login/codeload.gif");
      
        

        if (window != top) {
            top.location.href = getRootPath();
        }
        function changecode(obj) {
            if (obj != null) {
                var srcurl = projectName + "/index/validcode?t=" + Math.random();
                obj.src = srcurl;
            }
        }
        function loginCheck() {
            var username = document.getElementById("username");
            var password = document.getElementById("password");
            var checkcode = document.getElementById("checkcode");
            var msgbox = document.getElementById("msgbox");

            if (username.value.length == 0) {
                msgbox.innerHTML = "请输入用户名！";
                username.focus();
                return;
            }
            if (password.value.length == 0) {
                msgbox.innerHTML = "请输入用户密码！";
                password.focus();
                return;
            }
            if (checkCode && checkcode.value.length == 0) {
                msgbox.innerHTML = "请输入验证码！";
                checkcode.focus();
                return;
            }
            msgbox.innerHTML = "";
            $.ajax({
                type: "POST",
                dataType: "json",
                url: projectName + "/index/login",
                data: $('#submitForm').serialize(),
                success: function (data) {
                    var success = data.success;
                    console.log(data);
                    if (success) {
                        $.get(projectName + "/html/home/index.html", function (res) {
                            document.write(res);
                        });
                    } else {
                        document.getElementById("msgbox").innerHTML = data.message;
                    }

                },
                error: function (data) {
                    alert("error:" + data.responseText);
                }
            });

        }
        function nextEvent(strName) {
            if (strName == "login_btn") {
                loginCheck("");
            } else if (event.keyCode == 13) {
                event.keyCode = 9;
            }
        }
    </script>
</head>

<body>

   

  
        <div id="login_area" >
            <div id="login_box">
                <div id="login_sys">
                    <div id="login_sysName" style="font-size:40px;font-family:KaiTi">
                    </div>
                </div>
                <div id="login_form">
                    <form id="submitForm" name="submitForm" action="" method="post">
                        <div id="login_tip">
                            <span id="msgbox" class="sty_txt2"></span>
                        </div>
                        <div>
                            用户名：
                            <input id="username" type="text" name="username" class="username"
                                onkeydown="nextEvent('username');" />
                        </div>
                        <div>
                            密&nbsp;&nbsp;&nbsp;&nbsp;码：
                            <input id="password" type="password" name="password" class="password"
                                onkeydown="nextEvent('password');" />
                        </div>
                        <div id="login_form_checkcode" style="display:none;">
                            验证码：
                            <input type="text" id="checkcode" name="checkcode" class="checkcode" maxlength="4"/>
                            &nbsp;
                            <img border=0 src="#" onclick="changecode(this)" title="点击切换验证码"
                                style="vertical-align: bottom; cursor: pointer;" alt="点击重新加载" id="codeimg" />
                        </div>
                        <div id="btn_area">
                            <input type="button" class="login_btn" id="login_sub" name="login_btn" value="登  录"
                                onclick="loginCheck();" onkeydown="nextEvent('login_btn');">
                            <input type="reset" class="login_btn" id="login_ret" value="重 置">
                        </div>
                    </form>
                </div>
            </div>
        </div >
    </div>
</body>

</html>